Systemd minimal service
Table of Content
User Scope#
How to run systemd service run by unprivileged user
- place the service script in
~/.config/systemd/user - run systemctl command with
--userargument
demo#
mkdir -p ~/.config/systemd/user
[Unit]
Description=My new Service
[Service]
Type=simple
ExecStart=/bin/sh -c 'echo "hello service" >> /tmp/my_service.log 2>&1'
[Install]
WantedBy=default.target
systemctl --user enable minimal.service
systemctl --user daemon-reload
systemctl --user start minimal.service
system boot
OS run the service at boot time only when we set the WantedBy to default.target
systemctl with sudo oneliner#
echo <pass> | sudo -S <systemctl command>
#
echo <pass> | sudo -S <systemctl command>